package com.sunbeam.web.form;

import java.sql.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;

/**
 * @Title: LoginForm.java
 * @Package com.sunbeam.web.form
 * @Description: TODO
 * @author lyz lyzpoq_gmail_com
 * @date 2014/02/11 14:08:11
 * @version V1.0
 */
public class LoginForm {

	private String username;
	private String password;
	private String password2;
	private String birthday;
	private String email;
	private String nickname;
	private Map<String,String> errorMsgMap=new HashMap<String,String>();
	/**
	 * @return the errorMsgMap
	 */
	public Map<String, String> getErrorMsgMap() {
		return errorMsgMap;
	}
	/**
	 * @param errorMsgMap the errorMsgMap to set
	 */
	public void setErrorMsgMap(Map<String, String> errorMsgMap) {
		this.errorMsgMap = errorMsgMap;
	}
	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}
	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the password2
	 */
	public String getPassword2() {
		return password2;
	}
	/**
	 * @param password2 the password2 to set
	 */
	public void setPassword2(String password2) {
		this.password2 = password2;
	}
	/**
	 * @return the birthday
	 */
	public String getBirthday() {
		return birthday;
	}
	/**
	 * @param birthday the birthday to set
	 */
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @return the nickname
	 */
	public String getNickname() {
		return nickname;
	}
	/**
	 * @param nickname the nickname to set
	 */
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	//  username 3-8位英文字母
	//	password;6位以上18位以下英文数字符号
	//	password2;6位以上18位以下英文数字符号
	//	birthday;标准日期类型
	//	email;电子邮件格式
	//	nickname;汉字

	public boolean validate(){
		boolean isValid=true;
		if(username==null||username.trim().equals("")||!username.matches("^[A-Za-z]{3,8}$")){
			isValid=false;
			errorMsgMap.put("username", "用户名必须是3-8位字母！");
		}
		
		if(password==null||password.trim().equals("")||!password.matches("^[A-Za-z0-9.!@#$%^&*=+?~]{6,18}$")){
			isValid=false;
			errorMsgMap.put("password", "密码必须是6位以上18位以下英文数字符号");
		}
		if(password2==null||password2.trim().equals("")||!password2.matches("^[A-Za-z0-9.!@#$%^&*=+?~]{6,18}$")){
			isValid=false;
			errorMsgMap.put("password2", "密码必须是6位以上18位以下英文数字符号");
		}else if(!password2.equals(password)){
			isValid=false;
			errorMsgMap.put("password2", "第二次和第一次输入的密码不一致！");
		}
		
		try{
		DateLocaleConverter dlc=new DateLocaleConverter();
		dlc.convert(birthday, "yyyy-MM-dd");
		}catch(Exception e){
			isValid=false;
			errorMsgMap.put("birthday", "日期格式不对！");
		}
		
		if(email==null||email.trim().equals("")||!email.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")){
			isValid=false;
			errorMsgMap.put("email", "邮件格式不对！");
		}
		
		if(nickname==null||nickname.trim().equals("")||!nickname.matches("^[\u4e00-\u9fa5]{0,}$")){
			isValid=false;
			errorMsgMap.put("nickname", "昵称必须是汉字！");
		}
		return isValid;
	}
}

